<template>
  <view class="wrapper">
    <view class="remark"></view>
    <view class="title"> --------请选择你要发布的栏目-------- </view>
    <view class="menu">
      <view
        class="menu-item"
        v-for="(item, index) in typeList"
        :key="index"
        @click="onType(item)"
      >
        <view class="menu-item-icon">
          <image :src="cdnurl + item.img" class="menu-item-img"></image>
        </view>
        <view class="menu-item-name">{{ item.text }}</view>
      </view>
    </view>
    <typePost
      :show.sync="showType"
      :options="typeOptions"
      :typeName="typeName"
      @hide="showType=false"
      @change="onTypeChange"
    ></typePost>
  </view>
</template>

<script>
import config from "@/common/config/config.js";
import typePost from "@/components/wanl-local/type.vue";

export default {
  components: {
    typePost,
  },

  data() {
    return {
      typeList: [],
      outindex: 0,
      cdnurl: config.cdnurl,
      showType: false,
      typeOptions: [],
      typeName: "",
      typeAll: {
        26: [
          {
            value: 261,
            type: 26,
            text: "出租",
            title: '出租信息'
          },
          {
            value: 262,
            type: 26,
            text: "出售",
            title: '出售信息'

          },
          {
            value: 263,
            type: 26,
            text: "求租",
            title: '求租信息'

          },
          {
            value: 264,
            type: 26,
            text: "求购",
            title: '求购信息'

          },
        ],
        29: [
          {
            value: 291,
            type: 29,
            text: "车找人",
            title: '其他要求'

          },
          {
            value: 292,
            type: 29,
            text: "车找货",
            title: '其他要求'
          },
          {
            value: 293,
            type: 29,
            text: "顺丰车",
            title: '其他要求'
          },
        ],
        30: [
          {
            value: 301,
            type: 30,
            text: "求职",
            title: '自我评价'

          },
          {
            value: 302,
            type: 30,
            text: "招聘",
            title: '职位描述'
          },
        ],
      },
    };
  },
  async onLoad() {
    await this.loadData();
  },
  methods: {
    menuswiperchange(event) {
      this.outindex = event.detail.current;
    },
    async loadData() {
      await uni.request({
        url: "/wanlshop/local_life/getTypes",
        type: "get",
        success: (res) => {
          this.typeList = res.data;
        },
      });
    },
    onType(item) {
      if ([30, 26, 29].includes(item.value)) {
        this.typeOptions = this.typeAll[item.value];
        this.showType = true;
        this.typeName = item.text;
        return;
      }
      uni.navigateTo({
        url: "/pages/local/postDetail?type=" + item.value + "&title=" + encodeURIComponent(item.text),
      });
    },
    onTypeChange(type) {
      this.showType = false;
      uni.navigateTo({
        url: "/pages/local/postDetail?type=" + type.type + "&sub=" + type.value + "&title=" + encodeURIComponent(type.text), 
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.wrapper {
  width: 100%;
  min-height: 100vh;
  .remark {
    height: 300rpx;
  }
  .menu {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    flex-flow: row wrap;
    row-gap: 50rpx;
    margin: 50rpx 20rpx;
    .menu-item {
      width: 25%;
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
      flex-flow: column wrap;
      .menu-item-img {
        width: 72rpx;
        height: 72rpx;
      }
    }
  }
  .item-box {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    flex-flow: row wrap;
  }
  .title {
    font-size: 24rpx;
    font-weight: 500;
    color: #333;
    text-align: center;
    margin: 20rpx 0;
  }
  .menuwrapper {
    width: 700rpx;
    height: 360rpx;
    padding: 20rpx;
    box-sizing: border-box;
    margin: 20rpx auto;
    background: #f7f7f7;
    border-radius: 24rpx;

    .talkswiper {
      .talksitem {
        color: #333;
        font-size: 24rpx;

        image {
          width: 72rpx;
          height: 72rpx;
        }
      }
    }

    .dotwrpper {
      width: 100%;
      display: flex;
      justify-content: center;
      align-items: center;

      .dot {
        width: 40rpx;
        height: 5rpx;
        background: #aaa;
        margin-right: 20rpx;
      }

      .active {
        background: #1545c5 !important;
      }

      .act {
        background: #333;
      }
    }
  }
}
</style>
